package com.siki.vo.user;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.siki.pojo.commonEntity.SysUser;
import com.siki.pojo.enumeration.common.EducationClaim;
import com.siki.pojo.enumeration.common.PositionCategory;
import com.siki.pojo.enumeration.common.UserSex;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@ApiModel("用户信息返回VO")
@Getter
@Setter
@NoArgsConstructor
public class UserInfoVO {
    @ApiModelProperty(value = "真实姓名")
    private String realName;

    @ApiModelProperty(value = "性别")
    private String userSex;

    @ApiModelProperty(value = "居住地")
    private String address;

    @ApiModelProperty(value = "邮箱")
    private String email;

    @ApiModelProperty(value = "年龄")
    private Integer age;

    @ApiModelProperty(value = "头像url")
    private String avatarUrl;

    @ApiModelProperty(value = "毕业院校")
    private String graduatedSchool;

    @ApiModelProperty(value = "毕业时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime graduatedDate;

    @ApiModelProperty(value = "所学专业")
    private String profession;

    @ApiModelProperty(value = "学历")
    private String education;

    @ApiModelProperty(value = "职业意向类别")
    private String intention;

    @ApiModelProperty(value = "预期工资")
    private String expectedSalary;

    @ApiModelProperty(value = "预期工作地点")
    private String expectedCity;

    @ApiModelProperty(value = "自我介绍")
    private String selfIntroduction;

    public UserInfoVO(SysUser sysUser) {
        Optional.ofNullable(sysUser).ifPresent(user -> {
            //真实姓名
            this.realName=user.getRealName();
            Optional.ofNullable(user.getGeneralUser()).ifPresent(generalUser -> {
                BeanUtils.copyProperties(generalUser, this);
                //性别
                this.userSex = Optional.ofNullable(generalUser.getUserSex())
                        .map(UserSex::getName).orElse(null);
                //学历
                this.education = Optional.ofNullable(generalUser.getEducation())
                        .map(EducationClaim::getName).orElse(null);
                //职业意向
                this.intention = Optional.ofNullable(generalUser.getIntention())
                        .map(PositionCategory::getName).orElse(null);
            });
        });
    }
}
